package com.canaan.business.controller.pc.inOutStock;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.inOutStock.InStockBill;
import com.canaan.business.service.inOutStock.IInStockBillService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 入库单Controller
 *
 * @author canaan
 * @date 2025-03-29
 */
@Api(tags = "入库单")
@RestController
@RequestMapping("/inOutStock/inStockBill")
public class InStockBillController extends BaseController {
    @Resource
    private IInStockBillService inStockBillService;

    /**
     * 查询入库单列表
     */
    @ApiOperation(value = "查询入库单列表")
//    @PreAuthorize("@ss.hasPermi('inOutStock:inStockBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(InStockBill inStockBill) {
        startPage();
        List<InStockBill> list = inStockBillService.selectInStockBillList(inStockBill);
        return getDataTable(list);
    }

    /**
     * 导出入库单列表
     */
    @ApiOperation(value = "导出入库单列表")
    @PreAuthorize("@ss.hasPermi('inOutStock:inStockBill:export')")
    @Log(title = "入库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InStockBill inStockBill) {
        List<InStockBill> list = inStockBillService.selectInStockBillList(inStockBill);
        ExcelUtil<InStockBill> util = new ExcelUtil<InStockBill>(InStockBill.class);
        util.exportExcel(response, list, "入库单数据");
    }

    /**
     * 获取入库单详细信息
     */
    @ApiOperation(value = "获取入库单详细信息")
    @PreAuthorize("@ss.hasPermi('inOutStock:inStockBill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(inStockBillService.selectInStockBillById(id));
    }

    /**
     * 新增入库单
     */
    @ApiOperation(value = "新增入库单")
    @PreAuthorize("@ss.hasPermi('inOutStock:inStockBill:add')")
    @Log(title = "入库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InStockBill inStockBill) {
        return toAjax(inStockBillService.insertInStockBill(inStockBill));
    }

    /**
     * 修改入库单
     */
    @ApiOperation(value = "修改入库单")
    @PreAuthorize("@ss.hasPermi('inOutStock:inStockBill:edit')")
    @Log(title = "入库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InStockBill inStockBill) {
        return toAjax(inStockBillService.updateInStockBill(inStockBill));
    }

    /**
     * 删除入库单
     */
    @ApiOperation(value = "删除入库单")
    @PreAuthorize("@ss.hasPermi('inOutStock:inStockBill:remove')")
    @Log(title = "入库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(inStockBillService.deleteInStockBillByIds(ids));
    }
}
